<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/8/14
  Time: 17:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
  <head>
    <title>$Title$</title>
    <style>
      table tr:nth-child(even){
        background: lightgray;
      }
    </style>
  </head>
  <body>
    <table align="center" border="1px">
      <tr>
        <td colspan="5"><h1 align="center">图书信息</h1></td>
      </tr>
      <tr align="center">
        <th>图书名称</th>
        <th>图书作者</th>
        <th>购买时间</th>
        <th>图书分类</th>
        <th>操作</th>
      </tr>

      <c:forEach var="bookmanage" items="${sessionScope.list}">
      <tr align="center">
        <td>${bookmanage.name}</td>
        <td>${bookmanage.author}</td>
        <td>${bookmanage.time}</td>
        <c:choose>
          <c:when test="${bookmanage.type==1}">
            <td>计算机/软件</td>
          </c:when>
          <c:when test="${bookmanage.type==2}">
            <td>小说/文摘</td>
          </c:when>
          <c:otherwise>
            <td>杂项</td>
          </c:otherwise>
        </c:choose>
        <td><a href="javascript:void(0)" onclick="remove('${bookmanage.id}')">删除</a></td>
      </tr>
      </c:forEach>
    </table>
    <div style="margin-left: 550px" ><a href="add.jsp">新增图书信息</a></div>
    <script src="jq/jquery.js"></script>
    <script>
      function remove(id) {
        if(confirm('确认删除这本书吗？')) location.href='BookManageDelete?id='+id;
      }
      $(function () {
        if(${sessionScope.msg==true}){
          alert("删除成功");
        }else if(${sessionScope.msg==false}){
          alert("删除失败");
        }
        ${sessionScope.remove("msg")}

        if(${sessionScope.add==true}){
          alert("添加图书成功");
        }else if(${sessionScope.add==false}){
          alert("添加图书失败");
        }
        ${sessionScope.remove("add")}
      })
    </script>
  </body>
</html>
